/*
 * @Author: wwssaabb
 * @Date: 2021-08-02 15:18:17
 * @LastEditTime: 2021-08-06 11:55:52
 * @FilePath: \react-admin-server\public\test\test.js
 */
const fs=require('fs')
/* 

const allCategory=JSON.parse(fs.readFileSync('../category.json','utf-8'))

let arr_1=[]
let arr_2=[]
let arr_3=[]
allCategory.forEach((i,index)=>{
  arr_1.push({name:i.name,children:[]})
  i.category.forEach((_i,_index)=>{
    let obj={name:_i.name,children:[]}
    arr_1[index].children.push(obj)
    arr_2.push(obj)
    _i.category.forEach(__i=>{
      let obj={name:__i,goods:[]}
      arr_1[index].children[_index].children.push(obj)
      arr_2[index].children.push(obj)
      arr_3.push({name:__i,goods:[]})
    })
  })
})
 */
// console.log(arr_1)
// console.log(arr_2)
// console.log(arr_3)



// fs.writeFileSync('./test.json',JSON.stringify([{category_1:arr_1},{category_2:arr_2},{category_3:arr_3}]))

const py=require('pinyin')

let list=JSON.parse(fs.readFileSync('./users.json'))


list.map((i,index)=>{
  delete i._id
  i.name=i.username
  i.username=py(i.username,{style:py.STYLE_NORMAL}).join('')
  i.phone='15600000000'.slice(0,-(index.toString().length))+index
  i.role_id=i.role==='admin'?'610c9ef8141ed541448728b3':'610c9f4ee8d9f53918ff5535'
  delete i.role
})

console.log(list)

const {User}=require('../../model/user')

// fs.writeFileSync('./users1.json',JSON.stringify(list))

/* list.forEach(i=>{
  User.create(i).then(res=>console.log(res)).catch(err=>console.log(err.message))
}) */

User.find().then(res=>console.log(res))